package com.amado.course28Exception;

/*
继承RuntimeException的叫做运行时异常，不需要强制捕获异常
继承Exception的为检查性异常，必须捕获
捕获异常使用try catch finally


try {
	//代码
} catch (ArithmeticException e) {
} finally {
	System.out.println("最终执行");
}
 */
public class S02ExceptionFinally {
	public static void main(String[] args) {
		print();
//		getInt();
	}

	public static int print() {
		try {
			String a = null;
			System.out.println("try");
			a.toString();
			return 1;
		} catch (Exception e) {
			System.out.println("catch");
		}finally {
			System.out.println("finally");
		}
		System.out.println("end");
		return 0;
	}
	public static int getInt() {
		try {
			System.out.println("try");
			return 1;
		} catch (Exception e) {
			//有异常并且类型想匹配，或父异常匹配才进catch
			System.out.println("catch");
		}finally {
			//try中无论是否异常、返回值都会执行finally的代码
			System.out.println("finally");
		}
		System.out.println("end");
		//不写return 会报错
		return 0;
	}
}
